//
//  AY_BookReadTimeCell.m
//  AiYue
//
//  Created by boWen on 2023/11/14.
//

#import "AY_BookReadTimeCell.h"

@interface AY_BookReadTimeCell ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角

@property (nonatomic, strong) UIButton * clickBtn;
@property (strong,nonatomic) UIImageView * leftImgView;
@property (strong,nonatomic) UILabel * topTitleLabel;
@property (strong,nonatomic) UILabel * subTitleLbl;
@property (strong,nonatomic) UILabel * authorLabel;//作者
@end

@implementation AY_BookReadTimeCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}


- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(6) andAddSubView:self.contentView];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    
    self.leftImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(4) andAddSubView:self.bg_View];
    [self.leftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(YNUM(80));
        make.width.mas_equalTo(YNUM(58));
        make.left.equalTo(self.bg_View).offset(YNUM(16));
        make.centerY.equalTo(self.bg_View);
    }];
    
    self.clickBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:nil andFont:YFont(11) andTitleColor:COLOR(@"#F86923") andBg:COLOR(@"#F7F5F6") andImage:nil andBgImage:nil andTarget:self andAction:@selector(clickBookAction) andRadius:YNUM(16) andAddSubView:self.bg_View];
    [self.clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(YNUM(32));
        make.width.mas_equalTo(YNUM(68));
        make.right.equalTo(self.bg_View).offset(YNUM(-16));
        make.centerY.equalTo(self.bg_View);
    }];
    self.topTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftImgView.mas_top);
        make.left.equalTo(self.leftImgView.mas_right).offset(YNUM(12));
        make.right.equalTo(self.contentView).offset(-YNUM(15));
        make.height.mas_equalTo(YNUM(24));
    }];
    
    self.subTitleLbl = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#97A4B0") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.subTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topTitleLabel.mas_bottom).offset(YNUM(6));
        make.left.equalTo(self.topTitleLabel.mas_left);
        make.right.equalTo(self.clickBtn.mas_left).offset(YNUM(-12));
    }];
    
    self.authorLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#646D75") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.leftImgView.mas_bottom);
        make.left.equalTo(self.topTitleLabel.mas_left);
        make.right.equalTo(self.bg_View.mas_right).offset(YNUM(-14));
        make.height.mas_equalTo(YNUM(20));
    }];
    
}


- (void)setReadTModel:(ReadHistoryListModel *)readTModel {
    _readTModel = readTModel;
    
    [self.leftImgView sd_setImageWithURL:[NSURL URLWithString:kStringUtils(_readTModel.coverImg)] placeholderImage:YImage(@"placeholderImage")];
    self.topTitleLabel.text = kStringUtils(_readTModel.title);
    self.subTitleLbl.text = kStringUtils(_readTModel.info);
    self.authorLabel.text = [kStringUtils(_readTModel.latestReadTime) stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    
    if([kStringUtils(_readTModel.shelfFlag) isEqualToString:@"1"]) {
        //在书架
        [self.clickBtn setTitle:@"已加书架" forState:UIControlStateNormal];
        [self.clickBtn setTitleColor:COLOR(@"#909090") forState:UIControlStateNormal];
    }else {
        [self.clickBtn setTitle:@"加入书架" forState:UIControlStateNormal];
        [self.clickBtn setTitleColor:COLOR(@"#F86923") forState:UIControlStateNormal];
    }
}

- (void)clickBookAction {
    if(![kStringUtils(_readTModel.shelfFlag) isEqualToString:@"1"]) {
        if(self.addBookBlock) {
            self.addBookBlock();
        }
    }
}



@end
